const fs = require('fs');

function readFileBuffer(imageFilePath) {
	const stream = fs.createReadStream(imageFilePath);
	const imageChunks = [];// 存储文件流
	return new Promise((resolve) => {
		if (stream) { // 判断状态
			stream.on('data', (chunk) => {
				imageChunks.push(chunk);
			});
			stream.on('end', () => {
				const imageBuffer = Buffer.concat(imageChunks);
				resolve(imageBuffer);
			});
			stream.on('error', (error) => {
				throw error;
			});
		}
	});
}

module.exports = readFileBuffer;
